/*
 * Common.h
 *
 *  Created on: 2009-8-27
 *      Author: fanliangliang
 */

#ifndef COMMON_H_
#define COMMON_H_

#include <e32base.h>

/*
 * This enum discribes some time relative constant.
 */
enum {
	/*
	 * Default timeout for all socket operation.
	 */
	KDefaultTimeoutInSeconds = 15,
	
	/*
	 * Number of microseconds in one second.
	 */
	KMicroSecondsPerSecond = 1000000
};


/*
 * This enum describes the different states of a socket.
 */
enum TSocketState {
	/*
	 * The socket is not connected.
	 */
	EUnconnectedState,
	
	/*
	 * The socket is performing a hostname resolve.
	 */
	EResolvingState,
	
	/*
	 * The socket has started establishing a connection.
	 */
	EConnectingState,
	
	/*
	 * A connection is established with a remote host.
	 */
	EConnectedState,
	
	/*
	 * The socket is about to close.
	 */
	EClosingState
};


/*
 * This enum describes the socket errors that can occur.
 */
enum TSocketError {
	/*
	 * The remote host closed the connection.
	 * Note that the client socket will be closed after the remote close notification has been sent. 
	 */
	ERemoteHostClosed,
	
	/*
	 * The host address was not found or timeout.
	 */
	EHostNotFound,
	
	/*
	 * The connection was refused by remote host(i.e., the remote host was not listening on the specified port number)
	 * or timeout.
	 */
	ECannotConnect,
	
	/*
	 * A read operation failed.
	 */
	EReadError,
	
	/*
	 * A write operation failed.
	 */
	EWriteError,
	
	/*
	 * A read operation timeout.
	 */
	EReadTimeout,
	
	/*
	 * A write operation timeout.
	 */
	EWriteTimeout,
	
	/*
	 * The internal buffer for write operation was not sufficient.
	 * To handle this error, a client should wait for a few seconds and try again.
	 */
	EBufferOverflow
};


/*
 * This enum describes the timeout type which a socket can manipulate.
 */
enum TTimeoutType {
	/*
	 * Timeout type for read operation.
	 */
	ETimeoutTypeRead = 0x01,
	
	/*
	 * Timeout type for write operation.
	 */
	ETimeoutTypeWrite = 0x02,
	
	/*
	 * Timeout type for hostname resolve operation.
	 */
	ETimeoutTypeResolve = 0x04,
	
	/*
	 * Timeout type for connect operation.
	 */
	ETimeoutTypeConnect = 0x08,
	
	/*
	 * Timeout type for all operation above.
	 * It's very convenient for client to set the same timeout value for all operation.
	 */
	ETimeoutTypeAll = ETimeoutTypeRead | ETimeoutTypeWrite | ETimeoutTypeResolve | ETimeoutTypeConnect
};

#endif /* COMMON_H_ */
